/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package domain.controllers;

import domain.Entity.EntityTarea;
import domain.commands.TareaComando;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import managers.TareaManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;

/**
 *
 * @author jorge
 */
public class etiquetarController extends SimpleFormController {

   public etiquetarController() {
        setCommandClass(TareaComando.class);
  }
  
    @Override
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, org.springframework.validation.BindException errors) throws Exception {
   
        ModelAndView mav = new ModelAndView();
        HttpSession session = request.getSession();
        if(session == null){
            mav.setView(new RedirectView("login.htm"));
            return mav;
        }else{
        TareaManager tm = TareaManager.getInstance();
         
        TareaComando tc = (TareaComando) command;
        
       
        EntityTarea et = (EntityTarea) session.getAttribute("tarea");
        tm.etiquetar(et,tc.getEtiqueta());
        mav.setView(new RedirectView("mostrarTareas.htm"));
            
        
        return mav;
        }
    }

    
    
}
